package com.sskj.base.model;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;
import android.content.Context;

import com.sskj.base.data.User;
import com.sskj.base.utils.SPUtils;

public class UserViewModel extends ViewModel {

    private MutableLiveData<User> userLiveData;

    public LiveData<User> getUser(Context context) {
        if (userLiveData == null) {
            userLiveData = new MutableLiveData<>();
        }
        User user = (User) SPUtils.getBean(context, "user");
        userLiveData.setValue(user);
        return userLiveData;
    }

    public void setUser(Context context, User user) {
        SPUtils.putBean(context, "user", user);
        if (userLiveData == null) {
            userLiveData = new MutableLiveData<>();
        }
        userLiveData.postValue(user);
    }

}
